package com.cbw.blog.schedule;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cbw.blog.entity.Statistic;
import com.cbw.blog.mapper.StatisticMapper;
import com.cbw.blog.utils.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ScheduleTask {
    @Resource
    StatisticMapper statisticMapper;
    @Autowired
    MailUtils mailUtils;
    @Value("${spring.mail.username}")
    String mailTo;
//    @Scheduled(cron = "0 0/3 * * * ? ")
//    public void sendMessage(){
//        QueryWrapper<Statistic> select = new QueryWrapper<Statistic>().select("sum(hits) as hitsAll");
//        QueryWrapper<Statistic> select1 = new QueryWrapper<Statistic>().select("sum(comments_num) as commentsNumAll");
//        Statistic statistic = statisticMapper.selectOne(select);
//        Statistic statistic1 = statisticMapper.selectOne(select1);
//        Integer hitsAll = statistic.getHitsAll();
//        Integer commentsNumAll = statistic1.getCommentsNumAll();
//        StringBuffer buffer = new StringBuffer();
//        buffer.append("博客系统总访问量为"+hitsAll+"次").append("\n");
//        buffer.append("博客系统总评论为"+commentsNumAll+"次").append("\n");
//        mailUtils.sendSimpleEmail(mailTo,"个人博客系统流量统计",buffer.toString());
//
//    }
}
